import 'dart:developer';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:hprt_tscl/hprt_tscl.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: buildContent(context),
        ),
      ),
    );
  }

  Widget buildContent(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // TextButton(onPressed: () async {
        //   int res = (await HprtTscl.portOpen('00:15:83:03:F9:F3'))!;
        //   print(res);
        // }, child: const Text('connect')),
        TextButton(onPressed: () async {
          // await HprtTscl.selfTest();
          await HprtTscl.portClose();
          int? res = await HprtTscl.portOpen('00:15:83:03:FE:5D');
          log(res.toString());
          int? aa = await HprtTscl.printAreaSize(width: '65', height: '45');
          await HprtTscl.cls();
          // int? res1 = await HprtTscl.printQrCodeImage(
          //   data: "hello world#离离原上草一岁一枯荣",
          //   width: 300,
          //   height: 300,
          //   xpos: '10',
          //   ypos: '10',
          // );

          // int? vv = await HprtTscl.printText2(xpos: '10', ypos: '10', size: 4, codedata: '离离原上草一岁一枯荣');
          await HprtTscl.bold(1);
          await HprtTscl.printText(xpos: '0', ypos: '0', codedata: 'hello123：离离原上草一岁一枯荣', xmultiplication: '48', ymultiplication: '64');
          // await HprtTscl.printBlock(startX: 0, startY: 0, width: 100, height: 100, font: 1, content: '离离原上草一岁一枯荣');

          await HprtTscl.print(strnum: '1', strcopies: '1');


        }, child: const Text('setSelf')),


      ],
    );
  }


}
